
package com.snail.mobile.sim.oss.dictionaryinfo.dao.hibernate;

import java.util.Collection;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.sungrid.seine.oss.framework.dao.hibernate.BaseDaoHibernate;
import com.snail.mobile.sim.oss.dictionaryinfo.model.TblDictionaryInfoOss;
import com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao;

public class TblDictionaryInfoOssDaoHibernate extends BaseDaoHibernate implements TblDictionaryInfoOssDao 
{
    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#getTblDictionaryInfoOss(Integer nid)
     */
    public TblDictionaryInfoOss getTblDictionaryInfoOss(final Integer nid) 
    {
        TblDictionaryInfoOss tblDictionaryInfoOss = (TblDictionaryInfoOss) getHibernateTemplate().get(TblDictionaryInfoOss.class, nid);
        if (tblDictionaryInfoOss == null) 
        {
            log.warn("uh oh, tblDictionaryInfoOss with nid '" + nid + "' not found...");
            throw new ObjectRetrievalFailureException(TblDictionaryInfoOss.class, nid);
        }

        return tblDictionaryInfoOss;
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#saveTblDictionaryInfoOss(TblDictionaryInfoOss tblDictionaryInfoOss)
     */    
    public void saveTblDictionaryInfoOss(final TblDictionaryInfoOss tblDictionaryInfoOss) 
    {
        getHibernateTemplate().save(tblDictionaryInfoOss);
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#saveOrUpdateTblDictionaryInfoOss(TblDictionaryInfoOss tblDictionaryInfoOss)
     */    
    public void saveOrUpdateTblDictionaryInfoOss(final TblDictionaryInfoOss tblDictionaryInfoOss) 
    {
        getHibernateTemplate().saveOrUpdate(tblDictionaryInfoOss);
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#removeTblDictionaryInfoOss(Integer nid)
     */
    public void removeTblDictionaryInfoOss(final Integer nid) 
    {
        getHibernateTemplate().delete(getTblDictionaryInfoOss(nid));
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#getTblDictionaryInfoOsss(com.snail.mobile.sim.oss.dictionaryinfo.model.TblDictionaryInfoOss)
     */
    public List getTblDictionaryInfoOsss(final TblDictionaryInfoOss tblDictionaryInfoOss) 
    {
       //  return getHibernateTemplate().find("from TblDictionaryInfoOss order by nid desc");

        if (tblDictionaryInfoOss == null) 
        {
            return getHibernateTemplate().find("from TblDictionaryInfoOss");
        } else 
        {
            // filter on properties set in the tblDictionaryInfoOss
            HibernateCallback callback = new HibernateCallback() 
            {
                public Object doInHibernate(Session session) throws HibernateException 
                {
                    Example ex = Example.create(tblDictionaryInfoOss).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(TblDictionaryInfoOss.class).add(ex).addOrder(Order.desc("nid")).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#removeTblDictionaryInfoOsss(Collection tblDictionaryInfoOsss)
     */
    public void removeTblDictionaryInfoOsss(final Collection tblDictionaryInfoOsss)
    {
        getHibernateTemplate().deleteAll(tblDictionaryInfoOsss);
    }

    /**
     * @see com.snail.mobile.sim.oss.dictionaryinfo.dao.TblDictionaryInfoOssDao#saveTblDictionaryInfoOsss(Collection tblDictionaryInfoOsss)
     */
    public void saveTblDictionaryInfoOsss(final Collection tblDictionaryInfoOsss)
    {
        getHibernateTemplate().saveOrUpdateAll(tblDictionaryInfoOsss);
    }
}
